<template>
      <el-container class="home-contrainer">
        <el-header>
          <div>
            <img src="../assets/heima.png">
            <span>后台管理系统</span>
          </div>
          <el-button type="warning" @click="logOut">退出</el-button>
        </el-header>
        <el-container  >
          <!--侧边栏-->
          <el-aside :width="collapse? '86px': '200px'"  >
            <div class ="toggle-button" @click="toggleCollspa">|||</div>
            <el-menu
              default-active="1"
              class="el-menu-vertical-demo"
              @open="handleOpen"
              @close="handleClose"
              background-color="#545c64"
              text-color="#fff"
              :collapse="collapse"
              :collapse-transition="collapsetransition"
              active-text-color="#ffd04b"
              router="true">
              <!--router开启了路由模式-->
              <el-submenu v-for="(listone,index) in menuList" :index="listone.id+''" :key="index" class="el-submenu"><!--index不能相同，不然会相同的一级标签一起展开-->
                <!--一级菜单的名称-->
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>{{listone.authName}}</span>
                </template>

                <!--二级标签-->
                <el-menu-item-group>
                  <template slot="title">
                    <el-menu-item  v-for="(subItem,ind) in listone.children" :key="ind" :index="'/'+subItem.path+''" > 
                        <i class="el-icon-menu"></i>
                        <span>{{subItem.authName}}</span>
                    </el-menu-item>
                  </template>
                </el-menu-item-group>

                
               
              </el-submenu>
            
            </el-menu>
         
          </el-aside>
          <!--主题区域-->
          <el-main>
            <!--路由占位符-->
            <router-view/>
          </el-main>
        </el-container>
      </el-container>
</template>

<script>
export default {
  data() {
    return {
      menuList: [],
      collapse :false,
      collapsetransition:false

    };
  },
  created() {
    this.getMenuList();
  },
  methods: {
    //点击菜单的折叠
    toggleCollspa(){
     this.collapse=!this.collapse
    },
    logOut() {
      this.$confirm("确定退出登录？", "登出", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "退出登录!",
          });
          window.sessionStorage.clear();
          this.$router.push("/login");
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消登录",
          });
        });
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    async getMenuList() {
      await this.$http
        .get("menus")
        .then((data) => {
          console.log(data.data.data);
          this.menuList = data.data.data;
          //return data.data.data
        })
        .catch((error) => {
          console.log(error);
          return this.$message.error(error.data.data.meta.msg);
        });
    },
  },
};
</script>

<style lang="less" scope>
.el-submenu {
    list-style: none;
    //padding-right: 40px;
}

.home-contrainer {
  height: 900px;
}
.el-menu-vertical-demo {
  height: 100%;
}
.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  padding-left: 0%;
  align-items: center;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  line-height: 100%;
  height: 100%;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}
.toggle-button{
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #ffffff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>